package io.kiki.stack.http.feign.SpringMvcContract;

import io.kiki.stack.http.feign.Capability;
import io.kiki.stack.http.feign.InvocationHandlerFactory;
import org.springframework.cache.interceptor.CacheInterceptor;

/**
 * Allows Spring's @Cache* annotations to be declared on the feign client's methods.
 */
public class CachingCapability implements Capability {

    private final CacheInterceptor cacheInterceptor;

    public CachingCapability(CacheInterceptor cacheInterceptor) {
        this.cacheInterceptor = cacheInterceptor;
    }

    @Override
    public InvocationHandlerFactory enrich(InvocationHandlerFactory invocationHandlerFactory) {
        return new FeignCachingInvocationHandlerFactory(invocationHandlerFactory, cacheInterceptor);
    }

}
